package com.luff.thread.ThreadPool;

import java.util.concurrent.*;

/**
 * Create By The-Long time 2021/10/6 20:28
 **/

/*自定义线程池*/
public class MyThreadPoolExecutor extends ThreadPoolExecutor {

    //定义水总数
    public static Integer water = 1000;

    //定义单位放水数量
    public static int waterDischarge = 2;

    //定义任务调用按钮
    public static boolean isPause = false;//默认为运行

    public static boolean isDied= false;//默认存活
    /**
     * 自定义构造函数
     */
    public MyThreadPoolExecutor(int water, int waterDischarge, int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory, RejectedExecutionHandler handler) {
        super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler);
        this.water = water;
        this.waterDischarge = waterDischarge;
        System.out.println("上班啦，水池放入1000吨水;");
    }

    //当线程池任务执行前会执行此方法
    @Override
    protected void beforeExecute(Thread t, Runnable r) {
        super.beforeExecute(t, r);
    }

    /**
     * 自定义暂停所有线程方法
     */
    public void pause() {
        this.isPause=true;//设置为暂停
    }

    /**
     * 自定义唤醒方法
     */
    public void resume() {
        this.isPause=false; //设置为运行
    }

    /**
     * 杀死所有线程池的线程
     */
    public void killAll(){
        this.isDied=true;
    }

}
